package com.lz.football.module.friend.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.friend.vo.FriendVo;
	import com.lz.football.module.club.item.BaseItem;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.text.TextField;
	
	public class FriendItem extends BaseItem
	{
		/**
		 *名称  
		 */
		private var playerName:TextField;
		/**
		 *等级 
		 */
		private var Lv:TextField;
		/**
		 *vip 
		 */
		private var vip:TextField;
		private var _friendId:int;
		/**
		 *比赛结果 
		 */
		private var matchResult:MovieClip;
		
		/**
		 *结果容器 
		 */
		private var resultContain:MovieClip;
		public function FriendItem()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			if(view == null)
			{
				_skin = Reflection.createInstance("com.football.module.friend.friendItem");
				this.addChild(_skin);
			}
			else
			{
				_skin = view as MovieClip;
			}
			playerName = _skin.playerName;
			matchResult = _skin.matchResult;
			resultContain = _skin.resultContain;
			matchResult.gotoAndStop(2);
			Lv = _skin.Lv;
			vip = _skin.vip;
			super.initUI();
			reset();
		}
		/**
		 *重置 
		 * 
		 */
		override public function reset():void
		{
			playerName.text = "";
			Lv.text = "";
//			vip.visible = false;
			vip.text = "";
			super.reset();
			DisplayObjectUtil.removeAllChildren(contain);
			DisplayObjectUtil.removeAllChildren(resultContain);
			vip.textColor = 0x245B9C
			playerName.textColor = 0x000000
			Lv.textColor =0x000000
			contain.filters = null;
			callBack = null;
			data = null;
			matchResult.gotoAndStop(3);
			removeEvtListener();
		}
		override public function set data(value:Object):void
		{
			super.data = value;
			if(value == null)return;
			
			var friendVo:FriendVo = value as FriendVo;
			_friendId = friendVo.friendid;
//			vip.gotoAndStop(1);
			if(friendVo.VIP > 0)
				vip.text = "VIP" + friendVo.VIP;
			playerName.text = friendVo.uname + "";
			Lv.text = "Lv." + friendVo.level;
			vip.visible = true;
//			vip.text = "VIP9";
			var lo:MovieClip = Reflection.createInstance(AppData.getInstance().clubDatamanager.getTeamIconVo(friendVo.logo).iconurl);
			lo.scaleX = lo.scaleY = 0.2;
			lo.x = -lo.width >> 1;
			lo.y = -lo.height >>1;
			contain.addChild(lo);
			if(friendVo.offline == 2)
			{
				contain.filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0,0,0,1,0,])];
			}
			vip.textColor =0xFFCC00;
			playerName.textColor = 0xFFFFFF;
			Lv.textColor = 0xFFFFFF;
			addEvtListener();
			DisplayObjectUtil.removeAllChildren(resultContain);
			var mc:MovieClip;
			var win:int;//胜利场数 5则为全胜利 -5则全负 其他则有胜有负   1赢，2平，3输
			var result:Array = friendVo.friendResult;
			if(result == null)
			{
				mc.gotoAndStop(2);
				matchResult.gotoAndStop(2);
				return;
			}
			var len:int = result.length;
			//1赢，2平，3输  mc 1灰 2 绿 3 红
			for(var i:int = 0;i < len;i++)
			{
				mc = Reflection.createInstance("com.football.module.friend.matchStatus");
				mc.gotoAndStop(1);
				mc.x = resultContain.numChildren * (mc.width + 1)
				resultContain.addChild(mc);
				var m:int = result[i];
				switch(m)
				{
					case 1:
						
						mc.gotoAndStop(3);
						win++;
						break;
					case 2:
						mc.gotoAndStop(2);
						
						win = 0;
						break;
					case 3:
						
						mc.gotoAndStop(1);
						win--;
						break;
				}
				
			}
			if(win == 5)
			{
				matchResult.gotoAndStop(3);
			}else if(win == -5)
			{
				matchResult.gotoAndStop(1);
			}else
			{
				matchResult.gotoAndStop(2);
			}
			
//			ability.text = friendVo.ability + "";
//			time.text = "" + friendVo.time ;
		}
		/**
		 * 好友ID（好友俱乐部ID） 
		*/
			public function get friendId():int
			{
				return _friendId;
			}
			
			/**
			 * @private
			 */
			public function set friendId(value:int):void
			{
				_friendId = value;
			}
			
			/**
			 * 移出 
			 * @param event
			 * 
			 */
			override public function onMouseRollOut(event:MouseEvent):void
			{
				super.onMouseRollOut(event);
//				vip.textColor = 0x245B9C;
//				playerName.textColor = 0x000000
//				Lv.textColor =0x000000
			}
			
			/**
			 * 移上 
			 * @param event
			 * 
			 */
			override public function onMouseRollOver(event:MouseEvent):void
			{
				super.onMouseRollOver(event);
//					vip.textColor =0xFFCC00;
//				playerName.textColor = 0xFFFFFF;
//				Lv.textColor = 0xFFFFFF;
			}
	}
}